/*! \file VertexAccessor.cpp
 *	\brief 
 *
 *	created:	2010/12/13
 *	created:	13:12:2010   16:30
 *	filename: 	C:\src\tactics-engine\libs\gd\VertexAccessor.cpp
 *	file path:	C:\src\tactics-engine\libs\gd
 *	file base:	VertexAccessor
 *	file ext:	cpp
 *	author:		Vitalii Trubchaninov
 *				vitalii.trubchaninov@ubisoft.com
 */
#include "gd/stdafx.h"
#include "gd/VertexAccessor.h"

#include "gd/VertexBuffer.h"
#include "gd/VertexFormat.h"

namespace tt{
namespace gd{

VertexAccessor::VertexAccessor( DeviceContext* deviceContext, VertexBuffer& vertexBuffer, VertexFormat& vertexFormat )
: m_locker(deviceContext, vertexBuffer)
, m_data( reinterpret_cast<UInt8*>( vertexBuffer.data() ) )
, m_vertexSize(vertexFormat.vertexSize())
, m_positionOffset(vertexFormat.positionOffset())
, m_normalOffset(vertexFormat.normalOffset())
, m_colorOffset(vertexFormat.colorOffset())
{

}

VertexAccessor::~VertexAccessor()
{

}

void VertexAccessor::setPosition( UInt index, const math::Vector3F& value )
{
	math::Vector3F* positionPointer = vertexComponent(index, m_positionOffset);
	*positionPointer = value;
}

void VertexAccessor::setNormal( UInt index, const math::Vector3F& value )
{
	math::Vector3F* normalPointer = vertexComponent(index, m_normalOffset);
	*normalPointer = value;
}

void VertexAccessor::setColor( UInt index, const math::Vector3F& value )
{
	math::Vector3F* colorPointer = vertexComponent(index, m_colorOffset);
	*colorPointer = value;
}

//////////////////////////////////////////////////////////////////////////
math::Vector3F* VertexAccessor::vertexComponent( UInt index, UInt offset )
{
	UInt8* pointer = m_data + m_vertexSize * index + offset;
	return reinterpret_cast<math::Vector3F*>(pointer);
}

} //namespace gd
} //namespace tt